package com.huawei.appmarket.service.settings.card;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.activity.AbstractBaseActivity;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.service.settings.bean.BaseSettingCardBean;
import com.huawei.cloudservice.CloudAccountManager;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import o.awl;
import o.cdb;
import o.cdg;
import o.cfw;
import o.cgz;
import o.ckq;
import o.cku;
import o.BaseRequest;
import o.der;
import o.der.f;
import o.dge.d;
import o.dgh;
import o.dgo;
import o.dgt;
import o.dhq;
import o.diu;
import o.Logger;
import o.duj;
import o.duo;
import o.dvt;
import o.efp;
import o.egn;
import o.ehf;
import o.ekb;
import o.eoy;
import o.eqp;
import o.euf;
import o.evk;
import o.VideoNetChangeDialog;

public class SettingCancelProtocolCard extends BaseSettingCard {
    private String ˊ = UserSession.getInstance().getUserId();
    private cku ˋ;
    private boolean ˎ = false;
    private String ˏ = eqp.ॱ();
    private boolean ॱ = false;
    private OnClickListener ॱॱ = new OnClickListener(this) {
        final /* synthetic */ SettingCancelProtocolCard ˋ;

        {
            this.ˋ = r1;
        }

        public void onClick(View view) {
            this.ˋ.ˎ();
            dgh.onEvent(new d(this.ˋ.ᐝ, f.ﹳ).ˏ(KeyAndValue.NUMBER_01 + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˋ.ˊ + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˋ.ˏ).ˋ());
        }
    };

    class a implements awl {
        final /* synthetic */ SettingCancelProtocolCard ˋ;

        private a(SettingCancelProtocolCard settingCancelProtocolCard) {
            this.ˋ = settingCancelProtocolCard;
        }

        public void ˏ(boolean z, boolean z2) {
            Logger.ˎ("SettingCancelProtocolCard", "reject protocol, isAgree: " + z + " rtnCode=" + z2 + " hasLoginedWhenClickStop=" + this.ˋ.ॱ);
            if (!this.ˋ.ॱ) {
                this.ˋ.ʽ();
            } else if (!z2) {
                this.ˋ.ˊˋ.setClickable(true);
                evk.ˋ(this.ˋ.ᐝ, this.ˋ.ᐝ.getString(f.ˋʽ), 0).ˋ();
            } else if (z) {
                this.ˋ.ˊˋ.setClickable(true);
            } else {
                this.ˋ.ʼ();
            }
        }
    }

    public SettingCancelProtocolCard(Context context) {
        super(context);
        this.ᐝ = context;
    }

    public cgz ˏ(View view) {
        super.ˏ(view);
        ((TextView) view.findViewById(der.d.ʽʼ)).setText(f.ˌᐝ);
        ʽ(view);
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        this.ˊˋ.setOnClickListener(this.ॱॱ);
        if (cardBean instanceof BaseSettingCardBean) {
            BaseSettingCardBean baseSettingCardBean = (BaseSettingCardBean) cardBean;
            int ꜞ = baseSettingCardBean.ꜞ();
            if (ꜞ == 19622) {
                ˏ(ꜞ, baseSettingCardBean.ㆍ(), baseSettingCardBean.ꓸ());
                baseSettingCardBean.ʽ(0);
            }
        }
    }

    private void ˎ() {
        if (this.ᐝ instanceof Activity) {
            Logger.ˎ("SettingCancelProtocolCard", "onClickCancelProtocol");
            this.ˊˋ.setClickable(false);
            if (UserSession.getInstance().isLoginSuccessful()) {
                this.ॱ = true;
            } else {
                this.ॱ = false;
            }
            ˋ();
        }
    }

    private void ˋ() {
        if (this.ॱ) {
            this.ˋ = ehf.ˏ(this.ᐝ, ehf.class, this.ᐝ.getString(f.ˌᐝ), null);
        } else {
            this.ˋ = cku.ˏ(this.ᐝ, cku.class, this.ᐝ.getString(f.ˌᐝ), this.ᐝ.getString(f.ˍˏ));
        }
        this.ˋ.ˎ(this.ᐝ);
        this.ˋ.ॱ(-1, this.ᐝ.getResources().getString(f.ˌˎ));
        this.ˋ.ॱ(new ckq(this) {
            final /* synthetic */ SettingCancelProtocolCard ॱ;

            {
                this.ॱ = r1;
            }

            public void enableNetworking() {
                if (this.ॱ.ॱ) {
                    this.ॱ.ᐝ();
                } else {
                    this.ॱ.ˊ();
                }
            }
        });
        this.ˋ.ˎ(new OnDismissListener(this) {
            final /* synthetic */ SettingCancelProtocolCard ˋ;

            {
                this.ˋ = r1;
            }

            public void onDismiss(DialogInterface dialogInterface) {
                if (!this.ˋ.ˎ) {
                    this.ˋ.ˊˋ.setClickable(true);
                }
            }
        });
        this.ˋ.ˋ(new OnCancelListener(this) {
            final /* synthetic */ SettingCancelProtocolCard ˎ;

            {
                this.ˎ = r1;
            }

            public void onCancel(DialogInterface dialogInterface) {
                if (!this.ˎ.ˎ) {
                    this.ˎ.ˊˋ.setClickable(true);
                }
            }
        });
    }

    private void ˊ() {
        this.ˎ = true;
        cfw.ˎ(new dgt("stop_service"), new dgo("SettingCancelProtocolCard"));
        diu.ˊ().ˏ(new a());
        ekb.ˎ();
        VideoNetChangeDialog.ˏ(false);
    }

    private void ʽ() {
        dgh.ˏ();
        diu.ˊ().ॱ();
        duj.ˏ().ˎ(duo.class, new Object[0]);
        dhq.ॱ().ˊ();
        euf.ˎ().ॱॱ();
        dvt.ˏ().ˋ(1);
        eoy.ˊ(this.ᐝ);
        AbstractBaseActivity.sendUpgrade(this.ᐝ);
        egn.ˎ().ॱ();
    }

    private void ʼ() {
        cfw.ˎ(new efp(), new IServerCallBack(this) {
            final /* synthetic */ SettingCancelProtocolCard ˏ;

            {
                this.ˏ = r1;
            }

            public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
            }

            public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
                if (responseBean.getResponseCode() == 0 && responseBean.getRtnCode_() == 0) {
                    this.ˏ.ʽ();
                    return;
                }
                Logger.ˎ("SettingCancelProtocolCard", "Stop Service error: response.getResponseCode()=" + responseBean.getResponseCode() + " response.getRtnCode_()=" + responseBean.getRtnCode_());
                this.ˏ.ˊˋ.setClickable(true);
                evk.ˋ(this.ˏ.ᐝ, this.ˏ.ᐝ.getString(f.ˋʽ), 0).ˋ();
            }
        });
    }

    private void ᐝ() {
        if (((cdg) cdb.ॱ(cdg.class)).ॱॱ("com.huawei.hwid")) {
            try {
                ((Activity) this.ᐝ).startActivityForResult(CloudAccountManager.getPwdVerifyIntent(), 19622);
                return;
            } catch (Exception e) {
                ॱॱ();
                return;
            }
        }
        ॱॱ();
    }

    private void ॱॱ() {
        evk.ˋ(this.ᐝ, this.ᐝ.getString(f.ʿॱ), 0).ˋ();
        this.ˋ.dismiss();
        this.ॱ = false;
    }

    public void ˏ(int i, int i2, Intent intent) {
        Logger.ˎ("SettingCancelProtocolCard", "SettingCancelProtocolCard" + " onActivityResult resultCode=" + i2 + " requestCode=" + i);
        if (i == 19622 && intent != null) {
            if (-1 == i2) {
                ˊ();
                return;
            }
            ॱॱ();
        }
        this.ˊˋ.setClickable(true);
    }
}
